package com.nxy.test.netty.initializer;


import com.nxy.test.netty.handle.SimpleChatServerHandler;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.Delimiters;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

import java.nio.charset.Charset;

/**
 * Created by snailnan on 2017/3/1.
 */
public class ChatInitalizer extends ChannelInitializer<SocketChannel> {
    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline()
        .addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()))
        .addLast("decoder", new StringDecoder(Charset.forName("utf-8")))
        .addLast("encoder", new StringEncoder(Charset.forName("utf-8")))
        .addLast("handler", new SimpleChatServerHandler());
    }
}
